var db = require('../../models/project');
var extend = require('util')._extend;
var moment = require('moment');
var result = {};
/*
项目列表
 */
exports.projectList = function(req,res,next){


    var model = db.Project;
    
    db.sequelize.query("SELECT id,title FROM cases_case").spread(function (results, metadata) {
        
            result = results;
            
            return res.send(result);
    })
    .catch(function(error) {
            commonFuc.errorMsg(res,result,error);
    })

}

/*
项目详情
 */
exports.projectdetail = function(req,res,next){
    
    var id = req.query.id;

    db.sequelize.query("SELECT id, title, price, brief, attachment FROM cases_case WHERE id=" + id).spread(function (results, metadata) {

            results[0].attachment = "http://dunoinfo.com/medias/" + results[0].attachment;

            result = results;
            
            return res.send(result[0]);
        })
        .catch(function(error) {
            commonFuc.errorMsg(res,result,error);
        })

};

/*
项目类型
 */
exports.projectKind = function(req, res,next){

    var model = db.projectKind;

    db.sequelize.query("SELECT name,code FROM cases_casekind").spread(function(results, metadata){

        result = results;

        return res.send(result);

    }) 
    .catch(function(error){

    })
}

/*
项目图片
 */
exports.projectImage = function(req, res,next){

    var model = db.projectImage;

    db.sequelize.query("SELECT id, alt, attachment FROM cases_caseimage").spread(function(results, metadata){

        for (var i = 0; i < results.length; i++){
            results[i].attachment = "http://dunoinfo.com/medias/" + results[i].attachment;
        }

        result = results;

        return res.send(result);

    }) 
    .catch(function(error){

    })
}
